import globalAPI from '@/api/globalAPI'
import { request } from '@/api/service'

export const crudOptions = (vm) => {
  return {
    viewOptions: {
      componentType: 'row' // 查看对话框字段使用行组件
    },
    format: {
      response (ret) {
        return ret.data
      }
    },
    columns: [
      {
        title: '品牌',
        key: 'brandId',
        width: 90,
        search: { disabled: false },
        type: 'select',
        disabled: true,
        dict: {
          url: `${globalAPI.BASE_URL}/stb/brands/v1`,
          value: 'id', // value的属性名
          label: 'name', // label的属性名
          children: 'data',
          getData: (url, dict, { form, component }) => {
            return request({
              url: url,
              method: 'get'
            }).then(ret => { return ret.data })
          }
        },
        form: {
          rules: [ // 表单校验规则
            { required: true, message: '请选择品牌', trigger: 'blur' }
          ]
        }
      },
      {
        title: 'ID',
        key: 'id',
        width: 90,
        sortable: true,
        form: {
          disabled: true
        }
      },
      {
        title: '型号',
        width: 90,
        sortable: true,
        key: 'model',
        form: {
          rules: [ // 表单校验规则
            { required: true, message: '请输入型号名字', trigger: 'blur' },
            { type: 'string', required: true, pattern: /^[\u4e00-\u9fa5_a-zA-Z0-9]{2,200}$/, message: '由2到200个汉字数字字母下划线组成', trigger: 'blur' }
          ]
        }
      }
    ]
  }
}
